function operate(action)
{
	if(action == '') return;
	var f = form('BoardForm');
	var idlist = ''; 
	for (i=f.elements.length; i>0; i--)
	{
		if (f.elements[i-1].type.toLowerCase() == "checkbox")
		{
			if (f.elements[i-1].checked)
			{
				idlist += f.elements[i-1].value.toString() + ",";
			}
		}
	}
	idlist = idlist.substring(0, idlist.length - 1);
	if (idlist == '')
	{
		alert('没有选择任何记录行'); 
		return;
	}  
	
	if (action == 'move')
	{
		location.href = 'move.aspx?topicid=' + idlist;
	}
	else if (action == 'delete')
	{
		location.href = 'delete.aspx?topicid=' + idlist;
	}
	else if (action == 'subjectify')
	{
		location.href = 'subjectify.aspx?topicid=' + idlist;
	}
	else
	{ 
		f.action = 'operate.aspx?action=' + action;
		f.method = 'POST'
		f.submit();	
	}
}

function decorate(s)
{
	if(s == '') return;
	var f = form('BoardForm');
	var idlist = ''; 
	for (i=f.elements.length; i>0; i--)
	{
		if (f.elements[i-1].type.toLowerCase() == "checkbox")
		{
			if (f.elements[i-1].checked)
			{
				idlist += f.elements[i-1].value.toString() + ",";
			}
		}
	}
	idlist = idlist.substring(0, idlist.length - 1);
	if (idlist == '')
	{
		alert('没有选择任何记录行'); 
		return;
	}  
	
	f.action = 'operate.aspx?action=decorate&style=' + s;
	f.method = 'POST'
	f.submit();
}

function checkboard()
{
	var f = form('BoardForm');
	if (f.keyword.value == '')
		return false;
	location.href = 'search.aspx?boardid=' + f.boardid.value + '&type=body&keyword=' + unscape(f.keyword.value);
	return false;
}

var oldbulletincontent = '';
var boardid = null;
var editmode = false;
function modifybulletin(bid)
{
	if (editmode) return;
	editmode = true;
	boardid = bid;
	oldbulletincontent = html2ubb($('bulletin').innerHTML);
	$('bulletin').innerHTML = GetUbbEditor('bcontent', 15, '') + '<br /><textarea id="bcontent">' + oldbulletincontent + '</textarea><br /><div style="padding-top:5px;text-align:center;"><input type="button" value="&nbsp;&nbsp;&nbsp;确&nbsp;定&nbsp;&nbsp;&nbsp;" class="button" onclick="onsubmitmodfication()" />&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="&nbsp;&nbsp;&nbsp;取&nbsp;消&nbsp;&nbsp;&nbsp;" class="button" onclick="oncancelmodfication()" /></div>';
}

function onsubmitmodfication()
{
	
	editmode = false;
	var nc = $('bcontent').innerHTML;
	var request  = new Ajax(); 
	
	request.get("operate.aspx?action=ModifyBulletin&boardid=" + boardid + "&content=" + escape(nc) + "&timestamp=" + (new Date().getTime()));
	editmode = false;
	$('bulletin').innerHTML = ubb2html(nc);
}
function oncancelmodfication()
{
	editmode = false;
	$('bulletin').innerHTML = ubb2html(oldbulletincontent);
}

var readingtopicid = -1;
var waiting = false;
function previewtopic(img, topicid, page)
{
		if (waiting) return;
		
		if (img == null)
		{
			waiting = true;
			var request  = new Ajax(); 	
			request.get("preview.aspx?topicid=" + topicid + "&page=" + page  + "&timestamp=" + (new Date().getTime()), responsetopic);
			return;
		}
		
		var showtopic = $('showtopic' + topicid);
		if (showtopic == null)
		{
			readingtopicid = topicid;
			var obj = $('topicrow' + topicid);
			var table1 = obj.parentNode;
			
			var row1 = table1.insertRow(obj.rowIndex + 1);
			row1.id = 'showtopic' + topicid;
			row1.className = 'forumtd';
			  
			
			var cell1 = row1.insertCell(0); 
			cell1.colSpan = obj.cells.length;
			cell1.innerHTML = '<div class="allimg" style="text-align:center;" id="repliesoftopic' + topicid + '"><img src="' + img.src.replace('minus', 'loading').replace('plus', 'loading') + '" />&nbsp;&nbsp;数据加载中...</div>';
			img.src = img.src.replace('plus', 'minus');
			cell1.className = 'bg2';
			
			waiting = true;
			var request  = new Ajax(); 	
			request.get("preview.aspx?topicid=" + topicid + "&page=" + page  + "&timestamp=" + (new Date().getTime()), responsetopic);
		}
		else if (img.src.indexOf('plus.gif') > 1)
		{
			showtopic.style.display = '';
			img.src = img.src.replace('plus', 'minus');
		}
		else
		{
			showtopic.style.display = 'none';
			img.src = img.src.replace('minus', 'plus');
		}
}

function responsetopic(xmlobj)
{
	if (xmlobj.readyState == 4)
	{
		var response	= xmlobj.responseText;
		$('repliesoftopic' + readingtopicid).innerHTML = response;		
		waiting = false;
	}
}